-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Serial ID device target filter #84
base: develop
Are you sure you want to change the base?
Add Serial ID device target filter #84
Conversation
3083dc8
to
d33a555
Compare
d33a555
to
02f83f3
Compare
Thanks for implementing that. Please note that the way you implemented this (just taking the libusb device serial number) is not extremely useful for flashing: Case 1: Two picos are in bootloader mode In this case, both picos will present the same libusb device serial number, and you will not be able to select a specific one of them with Case 2: Two picos are connected and not in bootloader mode In this case, rebooting one of them and flashing it in one go with One workaround for this would be to remove the The only way to fix this completely is to extract the real serial number from devices in bootloader mode, which as I currently understand it requires execution of extractor code on the target pico as implemented in #80. (Which might not be desireable) A variant of |
TL;DR: if This is a much simpler solution to mine, and makes serial filters usable for most purposes. |
02f83f3
to
c4bb0a1
Compare
This should probably be targeting the |
@Ferdi265: Thanks for pointing this out to me.
I never knew the bootloader serial ID is not unique - I tested it on 2 board and each reported different serial - when I looked into it now, it seems each has different version of bootloader. I meant to address this with making I wonder if using the vendor device to read EEPROM serial id like in stdio_usb using
I could try to use the bus and address before the restart to narrow the search after the restart - the new device should be in the same bus/port but with different address. |
AFAIK, the bootrom command interface does not allow you to insert arbitrary SPI commands, so you can't use FLASH_RUID_CMD directly. The best way I found for now is to upload code into RAM that then reads out the serial using FLASH_RUID_CMD (see the code from my PR for that), not exactly a clean solution IMO. |
Yes, I looked at your code once I discovered your issue. I don't like the idea of code execution too, but it might be made safer based on knowledge of the bootrom code and version and only ever executed on devices with its specific VID/PID and known bootrom serial. I am now thinking it might be better to implement support for DFU load / save. That's where this filer would shine. |
You might want to look at my |
c4bb0a1
to
dc6d6bc
Compare
Yes, that's I meant by looking at you code 👍. I see you extracted the part dealing with extracting EEPROM serial into #86. When it gets merged, I will likely base this filter on it. For now, I think the path of least resistance, least duplicated effort, and most immediate usefulness means changing this filter to accept any device in bootrom after forced reboot. I also try to match it based on bus topology and position of the matched device prior to forced reboot. |
dc6d6bc
to
945f09e
Compare
945f09e
to
e478c65
Compare
In Also, I just tested a Pico 2, and it appears that the serial number for the bootloader is the same as the firmware! So we could just say that |
As you noticed, the USB serial number in bootloader mode is the same for all devices on rp2040. Having the serial check work for rp2040 even when in bootloader mode is very useful and should be there, otherwise flashing multiple rp2040s becomes a pain very fast. The suggestion with libusbp sounds good though! |
This PR is in response to #54 and improves usability of PR #83. This feature can be further improved by integrating the ability to read EEPROM serial number. This functionality is implemented in PR #86.
It adds
--serial <serial>
filter flag to device selection. The serial ID is then compared with string descriptor specified byiSerial
device configuration option.As the device in bootloader mode uses different serial than in firmware, changes need to made to filter setting in order to find the device after forced reset. If
--serial
option is specified and the device is forced to reboot by the selected command, filters are adjusted to match the device by combination of bus and port number of the device before the reboot.As per libusb docs for libusb_get_port_number:
This should be fine for matching immediately after automatic reboot for most cases.
This solution does NOT break backward compatibility - functionality and outputs do not change if the flag is not specified.
Usage:
For device matching after the reboot, I use internal USB port number filter. This filter can be easily exposed if considered useful for general use. I did not expose it right away to prevent feature creep and CLI option pollution without prior discussion.